import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/recipe/data/repository/recipe_repository.dart';
import 'package:casdon/modules/recipe/providers/recipe_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class RecipePutFavoriteUsecase {
  final RecipeRepository _repository;

  const RecipePutFavoriteUsecase(this._repository);

  Future<bool> execute({required String menuId}) async {
    try {
      var ret = await _repository.putRecipeCollect(menuId);

      return ret == 1 ? true : false;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("RecipePutFavoriteUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("RecipePutFavoriteUsecase 失败");
    }
  }
}

final recipePutFavoriteUsecaseProvider = Provider(
  (ref) => RecipePutFavoriteUsecase(ref.read(recipeRepository)),
);
